<?php
declare (strict_types = 1);

namespace app\sk\tpl;
use app\core\Res;


class ViewEdit extends Layui
{
    public function setFormInput($p){
        $this->_index['toform'][]=$p;
    }

    public function setJsLaydate($p){
        $this->_index['laydate'][]=$p;
    }

    public function seteditUrl($p){
        $this->_index['editurl']=$p;
    }
    

   public function view(){
        echo $this->header();
        $hiddenParams=['relation_id','relation_type'];
        $hiddenInput='';
        //$hiddenInput=$this->hiddenInputList($hiddenParams);
        $inputList='';
        $buttonList='';

        $cols='';
        $editurl='';
        $laydate='';
        foreach($this->_index as $key=>$v){
            if($key=='toform'){
                foreach($v as $toform){
                    $type=Res::kv($toform,'type');
                    if($type=='input'){
                        $inputList .=$this->formInput($toform);
                    }
                }
            }
            if($key=='laydate'){
                foreach($v as $k=>$val){
                    $laydate .= $val;
                }
            }

            if($key=='cols'){
                $cols=$v;
            }
            if($key=='editurl'){
                $editurl=$v;
            }
        }
       

        $buttonParams=[
        ];
        
        $buttonList .=$this->formAddButton($buttonParams);
        $searchForm1=[
            'FormId'=>'myForm',
            'hiddenInput'=>$hiddenInput,
            'inputList'=>$inputList,
            'buttonList'=>$buttonList,
        ];
        $formFrame=[
            'FormInfo'=>$this->searchForm1($searchForm1),
            'TableInfo'=>$this->searchTable1(['TableId'=>'myTable']),
        ];
        echo $this->formFrame1($formFrame);

        

       

        $jsParams=[
            'cols'=>$cols,
            'editurl'=>$editurl,
            'laydate'=>$laydate,
        ];
        echo $this->jsEdit($jsParams);
   }

}